import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询员工质检命中项分析
 */
export async function pageEtpEmployeeQualityChecks(params) {
  const res = await request.get('/etp/etpEmployeeQualityCheck/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部员工质检命中项分析
 */
export async function listEtpEmployeeQualityChecks(params) {
  const res = await request.get('/etp/etpEmployeeQualityCheck/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询员工质检命中项分析
 */
export async function getEtpEmployeeQualityCheck(id) {
  const res = await request.get('/etp/etpEmployeeQualityCheck/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加员工质检命中项分析
 */
export async function addEtpEmployeeQualityCheck(data) {
  const res = await request.post('/etp/etpEmployeeQualityCheck', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改员工质检命中项分析
 */
export async function updateEtpEmployeeQualityCheck(data) {
  const res = await request.put('/etp/etpEmployeeQualityCheck', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除员工质检命中项分析
 */
export async function removeEtpEmployeeQualityCheck(id) {
  const res = await request.delete('/etp/etpEmployeeQualityCheck/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除员工质检命中项分析
 */
export async function removeEtpEmployeeQualityChecks(ids) {
  const res = await request.delete('/etp/etpEmployeeQualityCheck/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出员工质检命中项分析
 */
export async function exportEtpEmployeeQualityChecks(params) {
  const res = await request({
    url: '/etp/etpEmployeeQualityCheck/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `etpEmployeeQualityCheck_${Date.now()}.xlsx`);
}
